#include <iostream>
#include "geometry.h"

int main()
{
   int n, m;
   std::vector<Point> res;
   Rectangle r;

   std::cin >> n;
   Point * points = new Point [n];

   for(int i = 0; i < n; i++)
      std::cin >> points[i];

   std::cin >> m;  

   for (int i = 0; i < m; i++)
   {
      std::cin >> r.lb.x >> r.lb.y;
      std::cin >> r.rt.x >> r.rt.y;
      res.clear();
      for (int j = 0; j < n; j++) 
      {
         if (in_rectangle(points[j], r))
            res.push_back(points[j]);
      }
      std::cout << res.size() << "\n";
      for (size_t j = 0; j < res.size(); j++)
      {
         std::cout << res[j].x << " " << res[j].y << "\n";
      }
   }

   return 0;
}